/**********热门景点路由器scenery.js************/
const express = require('express')
const pool = require('../pool.js')
const router = express.Router()
module.exports = router

//1.添加一个分页查询热门风景的路由器
//GET /list 参数pno=1&pageSize=3
//测试地址：http://127.0.0.1:8080/v1/scenery/list?pno=1&pageSize=3
router.get('/list',(req,res)=>{
	let pno = req.query.pno
	let ps = req.query.pageSize
	if(!pno){
		pno = 1
	}
	let start = (pno-1)*ps
	ps = ps?parseInt(ps):5
	let sql = `select * from scenery limit ?,? `
	pool.query(sql,[start,ps],(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})


//2.添加查询一个景点的接口
//GET /show
//请求参数:scenery_id=5
//请求地址:http://127.0.0.1:8080/v1/scenery/show?scenery_id=5
router.get('/show',(req,res)=>{
	let id = req.query.scenery_id
	id = parseInt(id)
	let sql = 'select * from scenery where scenery_id= ?'
	pool.query(sql,id,(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})

//3.添加一个查询指定季节景点的接口
//GET /seasonShow
//请求参数:seasonId=10                10-春 20-夏 30-秋 40-冬
//测试地址:http://127.0.0.1:8080/v1/scenery/seasonShow?seasonId=10
router.get('/seasonShow',(req,res)=>{
	let sid = req.query.seasonId
	sid = parseInt(sid)
	let sql = 'select * from scenery where seasonId=?'
	pool.query(sql,[sid],(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})

//4.添加一个查询指定地区景点的接口
//GET /areaShow
//请求参数:/:areaId                    1-定海区 2-普陀区 3-岱山区 4-溗泗县 5-朱家尖
//测试地址:http://127.0.0.1:8080/v1/scenery/areaShow/1
router.get('/areaShow/:areaId',(req,res)=>{
	let aid = req.params.areaId
	aid = parseInt(aid)
	let sql = 'select * from scenery where areaId=?'
	pool.query(sql,[aid],(err,result)=>{
		if(err) throw err
		res.send(result)
	})
})